package com.onluy.frameworkcloud.data.entity;


import java.io.Serializable;

public class OperColumn implements Serializable {
    private static final long serialVersionUID = 1L;
    private String operColumn;
    private String operColumnProperty;
    private Object operColumnValue;
    private Class<?> operColumnType;
    private String sort;
    private boolean isCondition;
    private Condition condition;

    public OperColumn(String operColumn, String operColumnProperty, Object operColumnValue, Class<?> operColumnType) {
        this.operColumn = operColumn;
        this.operColumnProperty = operColumnProperty;
        this.operColumnValue = operColumnValue;
        this.operColumnType = operColumnType;
    }

    public OperColumn asCondition() {
        this.isCondition = true;
        return this;
    }

    public OperColumn asOrderByAsc() {
        this.sort = "ASC";
        return this;
    }

    public OperColumn asOrderByDesc() {
        this.sort = "DESC";
        return this;
    }

    String getOperColumn() {
        return this.operColumn;
    }

    void setIsCondition(boolean isCondition) {
        this.isCondition = isCondition;
    }

    void cancelCondition() {
        this.setIsCondition(false);
    }

    boolean isCondition() {
        return this.isCondition;
    }

    public Condition getCondition() {
        if (this.condition == null) {
            this.condition = new Condition(this.operColumn);
        }

        return this.condition;
    }

    String getSort() {
        return this.sort;
    }

    Object getOperColumnValue() {
        return this.operColumnValue == null && !this.getCondition().isPre() && this.getCondition().getValues() != null
                && this.getCondition().getValues().length > 0
                ? this.getCondition().getValues()[0]
                : this.operColumnValue;
    }

    Class<?> getOperColumnType() {
        return this.operColumnType;
    }

    String getOperColumnProperty() {
        return this.operColumnProperty;
    }

    void setOperColumnValue(Object operColumnValue) {
        this.operColumnValue = operColumnValue;
    }
}